package com.gw.consumer1.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;
@Configuration
public class BeanConfig {
    //在Queue模式中，对消息的监听需要对containFactory(包含工厂)进行配置
    @Bean
    public JmsListenerContainerFactory<?> queueListenerFactory(ConnectionFactory connectionFactory) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setPubSubDomain(false); //点对点模式传输消息
        factory.setConnectionFactory(connectionFactory);
        return factory;
    }
    //在Topic模式中，对消息的监听需要对containFactory(包含工厂)进行配置
    @Bean
    public JmsListenerContainerFactory<?> topicListenerFactory(ConnectionFactory connectionFactory) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setPubSubDomain(true); //发布订阅模式传输消息
        factory.setConnectionFactory(connectionFactory);
        return factory;
    }
}
